added some development tools
[windows-sources.git] / developer / Samples / NET Standard / ParallelExtensionsExtras_Standard / ParallelAlgorithms / ParallelAlgorithms_Map.cs
blob722d95b39cd5ada4dfacf4ba66819c2790fa966d
1 //--------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // File: ParallelAlgorithms_Map.cs
6 //
7 //--------------------------------------------------------------------------
9 using System.Collections.Generic;
10 using System.Threading.Tasks;
12 namespace System.Threading.Algorithms
14 public static partial class ParallelAlgorithms
16 /// <summary>Executes a map operation, converting an input list into an output list, in parallel.</summary>
17 /// <typeparam name="TInput">Specifies the type of the input data.</typeparam>
18 /// <typeparam name="TOutput">Specifies the type of the output data.</typeparam>
19 /// <param name="input">The input list to be mapped used the transform function.</param>
20 /// <param name="transform">The transform function to use to map the input data to the output data.</param>
21 /// <returns>The output data, transformed using the transform function.</returns>
22 public static TOutput[] Map<TInput, TOutput>(IList<TInput> input, Func<TInput, TOutput> transform)
24 return Map(input, s_defaultParallelOptions, transform);
27 /// <summary>Executes a map operation, converting an input list into an output list, in parallel.</summary>
28 /// <typeparam name="TInput">Specifies the type of the input data.</typeparam>
29 /// <typeparam name="TOutput">Specifies the type of the output data.</typeparam>
30 /// <param name="input">The input list to be mapped used the transform function.</param>
31 /// <param name="parallelOptions">A ParallelOptions instance that configures the behavior of this operation.</param>
32 /// <param name="transform">The transform function to use to map the input data to the output data.</param>
33 /// <returns>The output data, transformed using the transform function.</returns>
34 public static TOutput[] Map<TInput, TOutput>(IList<TInput> input, ParallelOptions parallelOptions, Func<TInput, TOutput> transform)
36 if (input == null) throw new ArgumentNullException("input");
37 if (parallelOptions == null) throw new ArgumentNullException("parallelOptions");
38 if (transform == null) throw new ArgumentNullException("transform");
40 var output = new TOutput[input.Count];
41 Parallel.For(0, input.Count, parallelOptions, i => output[i] = transform(input[i]));
42 return output;